﻿<%@ WebHandler Language="C#" Class="Style" %>

using System;
using System.Web;

public class Style : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";

        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
        String path = "Data/design.xml";
        String realPath = context.Server.MapPath(path);
        xmlDoc.Load(realPath);

        System.Xml.XmlNodeList nodeListFont = xmlDoc.SelectNodes("/Design/Font");
        System.Xml.XmlNodeList nodeListBack = xmlDoc.SelectNodes("/Design/Background");

        // Font formatting
        for (int i = 0; i < 5; i++)
        {
            String response = String.Format("{0} {{size: {1};font-face: {2};color: {3};background-color: {4};}}", 
                nodeListFont[0].ChildNodes[i].Name.ToString(),
                nodeListFont[0].ChildNodes[i].ChildNodes[0].InnerText.ToString(),
                nodeListFont[0].ChildNodes[i].ChildNodes[1].InnerText.ToString(),
                nodeListFont[0].ChildNodes[i].ChildNodes[2].InnerText.ToString(),
                nodeListFont[0].ChildNodes[i].ChildNodes[3].InnerText.ToString());
            context.Response.Write(response);
            context.Response.Write(Environment.NewLine);
        }
        
        // Background-formatting
        for (int i = 0; i < 5; i++)
        {
            String response = String.Format("{0}{{background-color: {1};}}", 
                nodeListFont[0].ChildNodes[i].Name, 
                nodeListFont[0].ChildNodes[i].ChildNodes[0].InnerText.ToString());
            context.Response.Write(response);
            context.Response.Write(Environment.NewLine);
        }
        
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}